/**
 * Licensed under the MIT License
 *
 * Copyright (c) 2010 Laurent Berthelot
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy of
 * this software and associated documentation files (the "Software"), to deal in
 * the Software without restriction, including without limitation the rights to
 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
 * the Software, and to permit persons to whom the Software is furnished to do so,
 * subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 *
 */
package marcel.display.screen
{
	/**
	 * MarginProps class used by the ScreenManager class to define margins of objects on screen
	 * @author	Laurent Berthelot
	 */
	public class MarginProps extends Object
	{
		//--------------------------------------------------------------------------
		//
		//  Private vars
		//
		//--------------------------------------------------------------------------
		/**
		 * @private
		 */
		protected var _top:Number;
		/**
		 * @private
		 */
		protected var _right:Number;
		/**
		 * @private
		 */
		protected var _bottom:Number;
		/**
		 * @private
		 */
		protected var _left:Number;
		/**
		 * @private
		 */
		protected var _topIsPercent:Boolean;
		/**
		 * @private
		 */
		protected var _rightIsPercent:Boolean;
		/**
		 * @private
		 */
		protected var _bottomIsPercent:Boolean;
		/**
		 * @private
		 */
		protected var _leftIsPercent:Boolean;
		
		//--------------------------------------------------------------------------
		//
		//  Public vars
		//
		//--------------------------------------------------------------------------
		public var top:Number;
		public var right:Number;
		public var bottom:Number;
		public var left:Number;
		
		//--------------------------------------------------------------------------
		//
		//  Constructor
		//
		//--------------------------------------------------------------------------
		/**
		 * Constructs a new MarginProps instance
		 * @param	top				The top margin, in pixels or in percent [0->1]
		 * @param	right			The top right, in pixels or in percent [0->1]
		 * @param	bottom			The top bottom, in pixels or in percent [0->1]
		 * @param	left			The top left, in pixels or in percent [0->1]
		 * @param	topPercent		Indicates if the top property is in pixels (false) or in percent (true)
		 * @param	rightPercent	Indicates if the right property is in pixels (false) or in percent (true)
		 * @param	bottomPercent	Indicates if the bottom property is in pixels (false) or in percent (true)
		 * @param	leftPercent		Indicates if the left property is in pixels (false) or in percent (true)
		 */
		public function MarginProps(top:Number = 0, right:Number = 0, bottom:Number = 0, left:Number = 0, topPercent:Boolean = false, rightPercent:Boolean = false, bottomPercent:Boolean = false, leftPercent:Boolean = false) {
			_top = top;
			_right = right;
			_bottom = bottom;
			_left = left;
			_topIsPercent = topPercent;
			_rightIsPercent = rightPercent;
			_bottomIsPercent = bottomPercent;
			_leftIsPercent = leftPercent;
			updateProperties();
		}
		
		/**
		 * Updates top,right,bottom and left values.
		 * @param	wRef	the reference width container, generally the stage.stageWidth
		 * @param	hRef    the reference height container, generally the stage.stageHeight
		 */
		public function updateProperties(wRef:Number = 0, hRef:Number = 0):void {
			top = _updateProperty(_top, hRef, _topIsPercent);
			right = _updateProperty(_right, wRef, _rightIsPercent);
			bottom = _updateProperty(_bottom, hRef, _bottomIsPercent);
			left  = _updateProperty(_left, wRef, _leftIsPercent);
		}
		
		/**
		 * Returns the string representation of the specified object.
		 */
		public function toString():String {
			return "[MarginProps top : " + _top + " - right : " + _right + " - bottom : " + _bottom + " - left : " + _left + "]";
		}
		
		//--------------------------------------------------------------------------
		//
		//  Private methods
		//
		//--------------------------------------------------------------------------
		private function _updateProperty(value:Number, referer:Number = 0, isPercent:Boolean = false):Number {
			return isPercent ? value * referer : value;
		}
	}
}